package edu.je.prs.Controller;

import com.junqson.je.common.model.ApiResult;
import com.netflix.discovery.converters.Auto;
import edu.je.prs.Service.AnalyzeService;
import edu.je.prs.Service.UserService;
import edu.je.prs.util.EchartsUtil;
import edu.je.prs.Service.FrequencyService;
import edu.je.prs.vo.FrequencyArraysVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Set;

/**
 * @Description:
 * @author: Anhlaidh
 * @date: 2021-03-29 14:06
 */
@RestController
public class EchartsController {
    @Autowired
    FrequencyService frequencyService;
    @Autowired
    UserService userService;
    @Autowired
    AnalyzeService analyzeService;

    @RequestMapping(value = "/frequency/skill/all", method = RequestMethod.POST)
    public ApiResult getAllSkillFrequency() {
        HashMap<String, Integer> map = frequencyService.getAllSkillFrequency();

        if (map == null) {
            return ApiResult.error(500, "map is null");
        }
        return new ApiResult<>(200, "success", true, EchartsUtil.mapToList(map));

    }

    @RequestMapping(value = "/skills", method = RequestMethod.GET)
    public ApiResult getSkillsById(@RequestParam(name = "id") int id, HttpServletResponse response) {
        Set<String> set = frequencyService.getSkillsById(id);
        if (set == null) {
            return ApiResult.error(500, "set is null");
        }
        return ApiResult.success(set);
    }

    @RequestMapping(value = "/frequency/province/all", method = RequestMethod.GET)
    public ApiResult getAllProvinceFrequency() {
        HashMap<String, Integer> map = frequencyService.getAllProvinceFrequency();
        if (map == null) {
            return ApiResult.error(500, "map is null");
        }
        return ApiResult.success(EchartsUtil.mapToList(map));
    }

    @RequestMapping(value = "/frequency/province/array")
    public ApiResult getArrayOfProvinceFrequency() {
        FrequencyArraysVo vo = frequencyService.getArrayOfProvinceFrequency();

        if (vo == null || vo.getXdata() == null || vo.getXdata().length == 0) {
            return ApiResult.error(500, "no data");
        }
        return ApiResult.success(vo);

    }

    @RequestMapping(value = "/user/usertags")
    public ApiResult getUserTags(@RequestParam("id") int id) {
        return userService.getUserTags(id);
    }
    @RequestMapping("/frequency/education/all")
    public ApiResult getEducationFrequency(){
        HashMap<String, Integer> map = frequencyService.getAllEducationFrequency();

        if (map == null) {
            return ApiResult.error(500, "map is null");
        }
        return new ApiResult<>(200, "success", true, EchartsUtil.mapToList(map));
    }
    @RequestMapping("/frequency/experience/all")
    public ApiResult getExperienceFrequency(){
        HashMap<String, Integer> map = frequencyService.getAllExperienceFrequency();

        if (map == null) {
            return ApiResult.error(500, "map is null");
        }
        return new ApiResult<>(200, "success", true, EchartsUtil.mapToList(map));
    }
    @RequestMapping("/experience/analyze")
    public ApiResult analyzeExperience(){
        return analyzeService.analyzeExperience();
    }
    @RequestMapping("/correlation/analyze")
    public ApiResult analyzeCorrelation(){
        return analyzeService.analyzeCorrelation();
    }
    @RequestMapping("/frozen/analyze")
    public ApiResult analyzeFrozen(@RequestParam("id") int id){
        return analyzeService.analyzeFrozen(id);
    }
    @RequestMapping("/Popularity/analyze")
    public ApiResult analyzePopularity(@RequestParam("id") int id){
        return analyzeService.analyzePopularity(id);
    }

    @RequestMapping("/frozen/analyze/multi")
    public ApiResult multianalyzeFrozen(@RequestParam("id") int id){
        return analyzeService.multianalyzeFrozen(id);
    }

}
